﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.FileVersion", ServerTypeId="{96e4bc1b-e67f-4967-9327-36b79e20aebc}")]
    public class FileVersion : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public FileVersion(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                switch (peekedName)
                {
                    case "Created":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Created"] = reader.ReadDateTime();
                        return flag;

                    case "ID":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["ID"] = reader.ReadInt32();
                        return flag;

                    case "VersionLabel":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["VersionLabel"] = reader.ReadString();
                        return flag;

                    case "CreatedBy":
                        flag = true;
                        reader.ReadName();
                        this.CreatedBy.FromJson(reader);
                        return flag;

                    case "Url":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Url"] = reader.ReadString();
                        return flag;

                    case "IsCurrentVersion":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["IsCurrentVersion"] = reader.ReadBoolean();
                        return flag;

                    case "CheckInComment":
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["CheckInComment"] = reader.ReadString();
                        return flag;
                }
            }
            return flag;
        }

        [Remote]
        public string CheckInComment
        {
            get
            {
                base.CheckUninitializedProperty("CheckInComment");
                return (string) base.ObjectData.Properties["CheckInComment"];
            }
        }

        [Remote]
        public DateTime Created
        {
            get
            {
                base.CheckUninitializedProperty("Created");
                return (DateTime) base.ObjectData.Properties["Created"];
            }
        }

        [Remote]
        public User CreatedBy
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("CreatedBy", out obj2))
                {
                    return (User) obj2;
                }
                User user = new User(base.Context, new ObjectPathProperty(base.Context, base.Path, "CreatedBy"));
                base.ObjectData.ClientObjectProperties["CreatedBy"] = user;
                return user;
            }
        }

        [Remote]
        public int ID
        {
            get
            {
                base.CheckUninitializedProperty("ID");
                return (int) base.ObjectData.Properties["ID"];
            }
        }

        [Remote]
        public bool IsCurrentVersion
        {
            get
            {
                base.CheckUninitializedProperty("IsCurrentVersion");
                return (bool) base.ObjectData.Properties["IsCurrentVersion"];
            }
        }

        [Remote]
        public string Url
        {
            get
            {
                base.CheckUninitializedProperty("Url");
                return (string) base.ObjectData.Properties["Url"];
            }
        }

        [Remote]
        public string VersionLabel
        {
            get
            {
                base.CheckUninitializedProperty("VersionLabel");
                return (string) base.ObjectData.Properties["VersionLabel"];
            }
        }
    }
}

